In [2]:
import numpy as np
In [3]:
print(np.__version__)
In [4]:
a = np.array(range(10)) #파이썬의 배열을 입력 하면 넘파이 배열을 반환한다.
In [5]:
a
Out[5]:
In [6]:
type(a)
Out[6]:
In [7]:
b = [1,2,3]
In [8]:
a
Out[8]:
In [9]:
a = np.array([1,2,3])
b = np.array([10,20,30])
In [10]:
2 * a + b
Out[10]:
In [11]:
np.exp(a)
Out[11]:
In [12]:
np.log(b)
Out[12]:
In [13]:
np.sin(a)
Out[13]:
In [14]:
b = np.array([[0,1,2],[3,4,5]])
In [15]:
b.shape
Out[15]:
In [16]:
b
Out[16]:
In [17]:
len(b)
Out[17]:
In [18]:
len(b[0])
Out[18]:
In [19]:
c = np.array([[[1,2,3,4],[5,6,7,8],[9,10,11,12]],[[11,12,13,14],[15,16,17,18],[19,20,21,22]]])
In [20]:
c.shape
Out[20]:
In [21]:
c
Out[21]:
In [22]:
n = np.array([[0,0,1],[1,0,0]])
In [23]:
np.argmax(n,axis=0)
Out[23]:
In [24]:
print(c.ndim)
In [25]:
print(c.shape)
In [26]:
a = np.array(1)
In [27]:
a
Out[27]:
In [28]:
a.ndim
Out[28]:
In [29]:
a.shape
Out[29]:
In [30]:
a = np.array([1,2,3])
In [31]:
a.ndim
Out[31]:
In [32]:
a.shape
Out[32]:
In [33]:
a = np.array([[0,1,2],
[3,4,5]])
In [34]:
a.shape
Out[34]:
In [35]:
a.ndim
Out[35]:
In [36]:
a[0,2]
Out[36]:
In [37]:
a[-1,-1] # 마지막 행의 마지막 열
Out[37]:
In [38]:
a = np.array([[0,1,2,3],
[4,5,6,7]])
In [39]:
a[0,:]
Out[39]:
In [40]:
a[1,:]
Out[40]:
In [41]:
a[1,:2]
Out[41]:
In [42]:
a[:,1:3]
Out[42]:
In [43]:
a = np.array([0,1,2,3,4,5,6,7,8,9])
idx = np.array([True,False,True,False,True,False,True,False,True,False])
a[idx]
Out[43]:
In [44]:
a[a % 2 == 0]
Out[44]:
In [45]:
a = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) * 10
idx = np.array([0, 2, 4, 6, 8]) #위의 ndarray의 원소들의 인덱스들로 구성되어야 한다.
a[idx]
Out[45]:
In [46]:
a = np.array([0, 1, 2, 3]) * 10
idx = np.array([0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2])
a[idx]
Out[46]:
In [47]:
a = np.array([[1,2,3,4],
[5,6,7,8],
[9,10,11,12]])
a
Out[47]:
In [48]:
a[:, [True, False, False, True]]
Out[48]:
In [49]:
a[[2, 0, 1], :] #2번인덱스 0번인덱스 1번인덱스 순으로 행을 정렬한다.
Out[49]:
In [50]:
x = np.array([1.,2,3])
In [51]:
x.dtype
Out[51]:
In [52]:
np.exp(-np.inf)
Out[52]:
In [53]:
np.zeros(5)
Out[53]:
In [54]:
np.ones(10)
Out[54]:
In [55]:
np.zeros_like(3)
Out[55]:
In [56]:
np.array([1,2,3],dtype='float64')
Out[56]:
In [57]:
b = np.zeros((2,3,4),dtype='f8')
In [58]:
b
Out[58]:
In [59]:
c = np.zeros(5, dtype="S4")
In [60]:
c[0] = "abcd"
c[1] = "ABCDEF" #EF는잘린다.
In [61]:
c
Out[61]:
In [62]:
np.array([1,2,3],dtype=np.float32)
Out[62]:
In [63]:
np.array([1,2,3],dtype=np.int32)
Out[63]:
In [66]:
np.array([1,2,"3"],dtype=np.float32)
Out[66]:
In [ ]: